
package com.jf.cloud.order.service.impl;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.util.PageUtil;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.order.mapper.PurchaseOrderItemLangMapper;
import com.jf.cloud.order.model.PurchaseOrderItem;
import com.jf.cloud.order.model.PurchaseOrderItemLang;
import com.jf.cloud.order.service.PurchaseOrderItemLangService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 订单项-国际化
 *
 * @author zz
 * @date 2022-06-27 17:49:07
 */
@Service
public class PurchaseOrderItemLangServiceImpl implements PurchaseOrderItemLangService {

    @Autowired
    private PurchaseOrderItemLangMapper purchaseOrderItemLangMapper;

    @Override
    public PageVO<PurchaseOrderItemLang> page(PageDTO pageDTO) {
        return PageUtil.doPage(pageDTO, () -> purchaseOrderItemLangMapper.list());
    }

    @Override
    public PurchaseOrderItemLang getByPurchaseItemId(Long purchaseItemId) {
        return purchaseOrderItemLangMapper.getByPurchaseItemId(purchaseItemId);
    }

    @Override
    public void save(PurchaseOrderItemLang purchaseOrderItemLang) {
        purchaseOrderItemLangMapper.save(purchaseOrderItemLang);
    }

    @Override
    public void update(PurchaseOrderItemLang purchaseOrderItemLang) {
        purchaseOrderItemLangMapper.update(purchaseOrderItemLang);
    }

    @Override
    public void deleteById(Long purchaseItemId) {
        purchaseOrderItemLangMapper.deleteById(purchaseItemId);
    }

    @Override
    public void saveOrderItemLang(List<PurchaseOrderItem> purchaseOrderItems) {
        List<PurchaseOrderItemLang> orderItemLangList = new ArrayList<>();
        for (PurchaseOrderItem orderItem : purchaseOrderItems) {
            for (PurchaseOrderItemLang orderItemLang : orderItem.getPurchaseOrderItemLangList()) {
                orderItemLang.setPurchaseItemId(orderItem.getPurchaseItemId());
                orderItemLangList.add(orderItemLang);
            }
        }
        purchaseOrderItemLangMapper.saveBatch(orderItemLangList);
    }



}
